package cn.xy.ymcc.mq;

import cn.xy.ymcc.domain.MessageEmail;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EmailMessageProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送消息是否成功
     */
    public boolean sendMessage(MessageEmail messageEmail){
        String messageEmailJsonStr  = JSON.toJSONString(messageEmail);
        SendResult sendResult = rocketMQTemplate.syncSend("messageEmail-topic:messageEmail-tags", messageEmailJsonStr);
        //获取发送状态是否发送成功
        SendStatus sendStatus = sendResult.getSendStatus();
        return sendStatus == SendStatus.SEND_OK;
    }
}